#!/bin/sh

SERVICE_HOME=/mnt/iss/service/ticket-service/work/ticket-service-1
LIB_DIR=${SERVICE_HOME}/lib
LOGS_DIR=${SERVICE_HOME}/logs
ARCHIVE_SUFFIX=`date +%Y%m%d-%H%M`
MAIN_CLASS="OrderServer"
JAVA_ARGS="-server -Xms128m -Xmx128m -XX:NewSize=100m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=58 -XX:PermSize=64m -XX:MaxPermSize=192m -XX:ThreadStackSize=128 -Xloggc:${SERVICE_HOME}/logs/gc.log"

JAVA_ARGS="${JAVA_ARGS}  -Dsun.rmi.transport.tcp.readTimeout=5000  -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.server.exceptionTrace=true"


CLASSPATH=$CLASSPATH:${SERVICE_HOME}/classes/
files=`ls -1 ${LIB_DIR}`
for file in ${files} ;do
        CLASSPATH=$CLASSPATH:${LIB_DIR}/${file}
done

if [ -f ${LOGS_DIR}/stdout.log ] ; then
 mv ${LOGS_DIR}/stdout.log ${LOGS_DIR}/stdout.log.${ARCHIVE_SUFFIX}
fi;

if [ -f ${LOGS_DIR}/stderr.log ] ; then
 mv ${LOGS_DIR}/stderr.log ${LOGS_DIR}/stderr.log.${ARCHIVE_SUFFIX}
fi;

if [ -f ${LOGS_DIR}/gc.log ] ; then
 mv ${LOGS_DIR}/gc.log ${LOGS_DIR}/gc.log.${ARCHIVE_SUFFIX}
fi;

java -jar ticket-service-1.jar  1>/dev/null 2>${SERVICE_HOME}/logs/stderr.log&
